﻿using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Workshops.Commands;

/// <summary>
/// 更新车间信息命令。
/// </summary>
/// <param name="Workshop"></param>
public record UpdateWorkshopCommand(MdWorkshopDto Workshop) : IRequest<IResult<bool>>;

internal sealed class UpdateWorkshopCommandHandler(IRepository<MdWorkshop> repo) : IRequestHandler<UpdateWorkshopCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateWorkshopCommand request, CancellationToken cancellationToken)
    {
        var workshop = request.Workshop.Adapt<MdWorkshop>();
        var ok = await repo.UpdateAsync(workshop, m => new
        {
            m.WorkshopName,
            m.Remark,
            m.Status,
            m.UpdatedBy,
            m.UpdatedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
